package com.longteng.diamond.service;

import com.longteng.diamond.dao.BuildTestMapper;
import com.longteng.diamond.dao.InterfaceTestMapper;
import com.longteng.diamond.dao.TestCaseMapper;
import com.longteng.diamond.dao.UserMapper;
import com.longteng.diamond.domain.BuildTest;
import com.longteng.diamond.domain.InterfaceTest;
import com.longteng.diamond.domain.Metric;
import com.longteng.diamond.domain.TestCase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator
 * DATE : 2018/8/25
 * TIME : 22:46
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Component
public class IndexService {
    @Autowired
    InterfaceTestService interfaceTestService;
    @Autowired
    InterfaceTestMapper interfaceTestMapper;
    @Autowired
    TestCaseMapper testCaseMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    BuildTestMapper buildTestMapper;
    /**
     * 首页度量信息
     * @param projectId
     * @return Metric
     */
    public Metric getMetric(Integer projectId) {
        InterfaceTest interfaceTest = new InterfaceTest();
        interfaceTest.setProjectId(projectId);
        Long interfaceSize = interfaceTestMapper.queryAllRow(null);

        TestCase testCase = new TestCase();
        testCase.setProjectId(projectId);
        Long caseSize = testCaseMapper.queryAllRow(null);

        Integer userSize=userMapper.getAllUser().size();

        BuildTest buildTest=new BuildTest();
        buildTest.setProjectId(null);
        Integer buildSize = buildTestMapper.getBuildTest(buildTest).size();

        Metric metric=new Metric();
        metric.setBuildSize(buildSize);
        metric.setCaseSize(caseSize);
        metric.setInterfaceSize(interfaceSize);
        metric.setUserSize(userSize);
        return metric;
    }
    /**
     * 首页构建用例通过趋势
     * @param projectId
     * @return Metric
     */
    public List<BuildTest> buildTestRunMetric(Integer projectId){
      List<BuildTest> buildTestList  =buildTestMapper.findBuildTestGroupByDay(null);
      return buildTestList;
    }
    /**
     * 首页构建趋势
     * @param projectId
     * @return Metric
     */
    public List<Map> buildTrend(Integer projectId){
        List<Map> buildTestList  =buildTestMapper.findBuildSizeGroupByDay(null);
        return buildTestList;
    }
    /**
     * 计划构建趋势
     * @param buildTest
     * @return Metric
     */
    public List<BuildTest> testPlanRunMetric(BuildTest buildTest){
        List<BuildTest> buildTestList  = buildTestMapper.findBuildTestGroupByDay(buildTest);
        return buildTestList;
    }
}
